/**
 * 
 */
package hawk.example.juni5;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static java.util.Collections.singletonList;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/**
 * @author Hawk
 *
 */
public class TempDirectoryDemo {

	/**
	 * A test method that requires a temporary directory
	 */
	@Test
	void writeItemsToFile(@TempDir Path tempDir) throws IOException {
	    Path file = tempDir.resolve("test.txt");

	    new ListWriter(file).write("a", "b", "c");

	    assertEquals(singletonList("a,b,c"), Files.readAllLines(file));
	}
	
	/**
	 * A test method that requires multiple temporary directories
	 */
	@Test
	void copyFileFromSourceToTarget(@TempDir Path source, @TempDir Path target) throws IOException {
	    Path sourceFile = source.resolve("test.txt");
	    new ListWriter(sourceFile).write("a", "b", "c");

	    Path targetFile = Files.copy(sourceFile, target.resolve("test.txt"));

	    assertNotEquals(sourceFile, targetFile);
	    assertEquals(singletonList("a,b,c"), Files.readAllLines(targetFile));
	}
}
